import { Router } from 'express';
import Payload from '../models/Payload'
import RequestUtil from '../lib/RequestUtil'

export default () => {
	let api = Router();

	// perhaps expose some API metadata at the root
	api.get('/', (req, res) => {
		//get 请求获取参数
		const token = req.query.token;
		res.json(new Payload({
			token : token,
			name : 'foo'
		}));
	})

	api.all('/', (req,res) => {
		//post 请求获取body内容
		let body = req.body;
		res.json(new Payload({
			token : req.query.token,
			body : body
		}));
	})

	api.get('/req/test/get', async (req,res) => {
		const ru = new RequestUtil();
		const result = await ru.get('/api');
		res.json (new Payload(result));
	})

	api.get('/req/test/delete',async (req,res) => {
		const ru = new RequestUtil();
		const result = await ru.delete('/api',{
			token : 'lwx'
		});
		res.json (new Payload(result));
	})

	api.get('/:id', (req,res) => {
		//获取url上的参数
		const id = req.params.id;
		res.json({id : id});
	})

	return api;
}
